﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class ChuyenMonInfo
    {
        public string ChuyenMonID{get;set;}
        public string TenChuyenMon{get;set;}
        public bool Active { get; set; }
    }
    class ChuyenMonCtr
    {
        string StrCnn = DBClass_FANIT82.GetConnectString();
        public void Insert(ChuyenMonInfo Item) {
            SqlParameter[] Param = new SqlParameter[]{
            new SqlParameter("@ChuyenMonID",Item.ChuyenMonID),
            new SqlParameter("@TenChuyenMon",Item.ChuyenMonID==null? (object) DBNull.Value:Item.TenChuyenMon),
            new SqlParameter("@Active",Item.ChuyenMonID==null?(object)DBNull.Value:Item.Active)};
            SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_ChuyenMon_Insert", Param);
        }

        public void Update(ChuyenMonInfo Item) 
        {
            SqlParameter[] Param = new SqlParameter[]{
            new SqlParameter("@ChuyenMonID",Item.ChuyenMonID),
            new SqlParameter("@TenChuyenMon",Item.ChuyenMonID==null? (object) DBNull.Value:Item.TenChuyenMon),
            new SqlParameter("@Active",Item.ChuyenMonID==null?(object)DBNull.Value:Item.Active)};
            SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_ChuyenMon_Update", Param);        
        }
        public void Delete(String ChuyenMonID) 
        {
            SqlParameter Param = new SqlParameter("@ChuyenMonID", ChuyenMonID);
            SqlHelper.ExecuteNonQuery(StrCnn, CommandType.StoredProcedure, "D_ChuyenMon_Delete", Param);        
        }
        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(StrCnn, CommandType.StoredProcedure, "D_ChuyenMon_GetList");
            return Ds.Tables[0];
        }
        public ChuyenMonInfo GetByID(String ChuyenMonID)
        {
            SqlDataReader MyReader = SqlHelper.ExecuteReader(StrCnn, CommandType.StoredProcedure, "D_ChuyenMon_Get", new SqlParameter("ChuyenMonID", ChuyenMonID));
            ChuyenMonInfo ReturnObject = null;
            while (MyReader.Read())
            {
                ReturnObject = new ChuyenMonInfo();
                ReturnObject.ChuyenMonID = MyReader["ChuyenMonID"].ToString();
                ReturnObject.TenChuyenMon = MyReader["TenChuyenMon"].ToString();
                ReturnObject.Active = (bool)MyReader["Active"];
            }
            return ReturnObject;
        }
    }
}
